package linkedlist.exercise;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class MainClass {
    public static int[] stringToIntegerArray(String input) {
        input = input.trim();
        input = input.substring(1, input.length() - 1);
        if (input.length() == 0) {
          return new int[0];
        }
    
        String[] parts = input.split(",");
        int[] output = new int[parts.length];
        for(int index = 0; index < parts.length; index++) {
            String part = parts[index].trim();
            output[index] = Integer.parseInt(part);
        }
        return output;
    }
    
    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while ((line = in.readLine()) != null) {
            int[] nums = stringToIntegerArray(line);
            line = in.readLine();
            int target = Integer.parseInt(line);
            
            int ret = new Solution().search(nums, target);
            
            String out = String.valueOf(ret);
            
            System.out.print(out);
        }
    }

    public int search(int[] nums, int target) {
        return bsearch(nums, 0, nums.length - 1, target);
    }

    public int bsearch(int[] nums, int l, int r, int target) {
        if(l > r) return -1;
        int pivot = l + ((r - l) >> 1);
        if(nums[pivot] == target) {
            return pivot;
        } else if(nums[pivot] > target) {
            return bsearch(nums, l, pivot - 1, target);
        } else {
            return bsearch(nums, pivot + 1, l, target);
        }
    }
}